package com.hnust.controller;

import com.cleveroom.core.KLWCommunicater;
import com.cleveroom.exception.CleveroomConnException;
import com.hnust.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/4/21
 * 描述：
 */
@Slf4j
@RestController
@RequestMapping("/connect")
@CrossOrigin("*")
public class ConnectController {
    @Autowired
    private KLWCommunicater klwCommunicater;
    @GetMapping("/open")
    public R<String> connect() throws CleveroomConnException {
        //klwCommunicater.clearCache();
        if(klwCommunicater.connect()){
            klwCommunicater.startEngine();
        }
        return R.success("开启成功");
    }
    @GetMapping("/close")
    public R<String> close() {
        klwCommunicater.release();
        return R.success("关闭成功");
    }
}
